import api from '../api';

const getListAsync = async (data) => {
  return await api.postWithToken({
    command: 'I_Role_GetRoles',
    data
  });
};

const addAsync = async (data) => {
  return await api.postWithToken({
    command: 'I_Role_New',
    data
  });
};

const editAsync = async (data) => {
  return await api.postWithToken({
    command: 'I_Role_Modify',
    data
  });
};

const deleteAsync = async (id) => {
  return await api.postWithToken({
    command: 'I_Role_Delete',
    data: {
      role_id: id
    }
  });
};

const setPowersAsync = async (role_id, power_ids) => {
  return await api.postWithToken({
    command: 'I_Role_SetPowers',
    data: {
      role_id: role_id,
      powers: power_ids,
    }
  });
};

const getPowersAsync = async (role_id) => {
  return await api.postWithToken({
    command: 'I_Role_GetPowers',
    data: {
      role_id: role_id,
      page_index: 1,
      page_size: 999
    }
  });
};

export default {
  getListAsync,
  addAsync,
  editAsync,
  deleteAsync,
  setPowersAsync,
  getPowersAsync
}